/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.businessservice.common.service.impl;


import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.adminCode;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.admin_code;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.smallscale_station;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.water_station;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.contour_setting;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.sys_config;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.potential_points;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.river_basin;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.summary_product;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.ElemContourSet;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.MsgMediumSmallScale;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.SmallScaleStation;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.WaterStation;
import com.dmgis.qxfw.dataservice.businessservice.common.service.IConfigService;
import com.dmgis.qxfw.dataservice.businessservice.common.util.JsonUtil;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.commonservice.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.pages.service.impl.ComDisplayServiceImpl;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.persistence.Id;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.SecureRandom;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

/**
 * This class is used for ...
 *
 * @author dsq
 * @version 1.0, 2018年6月27日 上午9:33:00
 */
@Service("CommonService")
public class ConfigService implements IConfigService {
    ProcessRequestController pc = new ProcessRequestController();
    private static final Logger log = Logger.getLogger(ComDisplayServiceImpl.class);

    @Override
    public List<SmallScaleStation> getCitySta() {
        // TODO 城市站点
        /*
         * DbContextHolder.setDbType("qx"); return configDao.getCitySta();
         */
        List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
        List<smallscale_station> dataList = new ArrayList<smallscale_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            // 获取查询字段
            List<String> columns = new ArrayList<String>();
            columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
            columns.add("StationName");
            columns.add("longitude");
            columns.add("latitude");
            columns.add("city");
            columns.add("county");
            selectRequest.setParam(
                    String.format("stationid like '5%%' and city like '%s%%'", DbConfig.CITY));
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (smallscale_station station : dataList) {
                    SmallScaleStation scaleStation = new SmallScaleStation();
                    scaleStation.setCity(station.getCity());
                    scaleStation.setAltitude(station.getAltitude());
                    scaleStation.setCounty(station.getCounty());
                    scaleStation.setLatitude(station.getLatitude());
                    scaleStation.setStationID(station.getStationid());
                    scaleStation.setStationName(station.getStationname());
                    resultList.add(scaleStation);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public List<potential_points> getCountry() {
        // TODO 城市站点
        /*
         * DbContextHolder.setDbType("qx"); return configDao.getCitySta();
         */
        List<potential_points> resultList = new ArrayList<potential_points>();
        List<potential_points> dataList = new ArrayList<potential_points>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            // 获取查询字段
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectRequest.setColumns(new String[]{"distinct county"});
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<SmallScaleStation> getTownStaList() {
        // TODO 自动站
        List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
        List<smallscale_station> dataList = new ArrayList<smallscale_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            // 获取查询字段
            List<String> columns = new ArrayList<String>();
            columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
            columns.add("StationName");
            columns.add("longitude");
            columns.add("latitude");
            columns.add("city");
            columns.add("county");
            selectRequest.setParam(String.format("county like '%s%%'", DbConfig.COUNTY));
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (smallscale_station station : dataList) {
                    SmallScaleStation scaleStation = new SmallScaleStation();
                    scaleStation.setCity(station.getCity());
                    scaleStation.setAltitude(station.getAltitude());
                    scaleStation.setCounty(station.getCounty());
                    scaleStation.setLatitude(station.getLatitude());
                    scaleStation.setLongitude(station.getLongitude());
                    scaleStation.setStationID(station.getStationid());
                    scaleStation.setStationName(station.getStationname());
                    resultList.add(scaleStation);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public List<sys_config> getSysConfig(String ParamType) {
        // TODO 获取系统参数配置信息
        List<sys_config> data = new ArrayList<sys_config>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(String.format("ParamType='%s'", ParamType));
            selectParam.put("method", "sys_config");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            data = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sys_config>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }

        return data;
    }

    @Override
    public List<ElemContourSet> getElemContourSet(String elementType) {
        // TODO 获取图例
        List<contour_setting> dataList = new ArrayList<contour_setting>();
        List<ElemContourSet> resultList = new ArrayList<ElemContourSet>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            if (elementType.equals("evaporation")) {

            } else {
                selectRequest.setParam(String.format("ElementType='%s'", elementType));
                selectRequest.setSort(new String[]{"elementvalue asc"});
            }

            selectParam.put("method", "contour_setting");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<contour_setting>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (contour_setting setting : dataList) {
                    ElemContourSet elemSet = new ElemContourSet();
                    elemSet.setElementColor(setting.getElementcolor());
                    elemSet.setElementValue(setting.getElementvalue());
                    elemSet.setElemrntInstruction(setting.getElemrntinstruction());
                    resultList.add(elemSet);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    @Override
    public List<adminCode> getTown() {
        // TODO 县点
        List<adminCode> resultList = new ArrayList<adminCode>();
        List<admin_code> dataList = new ArrayList<admin_code>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" length(advcode)=6 and advcode like'" + DbConfig.advCode.substring(0, 4) + "%' and substr(advcode,5,6) != '00'");
            selectParam.put("method", "admin_code");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<admin_code>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (admin_code admin : dataList) {
                    adminCode adminCode = new adminCode();
                    adminCode.setAdvcode(admin.getAdvcode());
                    adminCode.setAdvname(admin.getAdvname());
                    resultList.add(adminCode);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public List<WaterStation> getRainSta() {
        // TODO 雨量站点
        List<WaterStation> resultList = new ArrayList<WaterStation>();
        List<water_station> dataList = new ArrayList<water_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"DISTINCT stnm", "stcd"});
            selectRequest.setParam(" addvcd like'" + DbConfig.advCode.substring(0, 4) + "%' and (sttp = 'PP' or sttp = 'MM')");
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (water_station station : dataList) {
                    WaterStation waterStation = new WaterStation();
                    waterStation.setStnm(station.getStnm());
                    waterStation.setStcd(station.getStcd());
                    resultList.add(waterStation);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public List<SmallScaleStation> getStion() {
        // TODO 乡镇站点
        List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
        List<smallscale_station> dataList = new ArrayList<smallscale_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"DISTINCT(stationid),stationname"});
            selectRequest.setParam(
                    " evaporation<>-65535 ");
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (smallscale_station station : dataList) {
                    SmallScaleStation scaleStation = new SmallScaleStation();
                    scaleStation.setStationName(station.getStationname());
                    resultList.add(scaleStation);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }


//    @Override
//    public Map<String,Object> getSmallScaleStation() {
//        // TODO 乡镇站点
//        List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
//        List<smallscale_station> stationList = new ArrayList<smallscale_station>();
//        List<smallscale_station> dataList = new ArrayList<smallscale_station>();
//        Map<String, Object> dataMap = new HashMap<>();
//        try {
//            //查询国家站站点
//            Map<String, String> selectParam = new HashMap<String, String>();
//            RequestDataBySelect selectRequest = new RequestDataBySelect();
//            selectRequest.setColumns(new String[]{"distinct stationname"});
//            selectRequest.setParam("city like '"+DbConfig.CITY+"%' and stationid like '5%'");
//            selectParam.put("method", "smallscale_station");
//            selectParam.put("sqlType", "select");
//            selectParam.put("param", JsonUtil.object2Json(selectRequest));
//            String message = pc.processRequest(selectParam);
//            stationList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
//            });
//            if (stationList != null && stationList.size() > 0) {
//                for (smallscale_station station : stationList) {
//                    selectParam = new HashMap<String, String>();
//                    selectRequest = new RequestDataBySelect();
//                    selectRequest.setColumns(new String[]{"stationname"});
//                    selectRequest.setParam("city like '"+DbConfig.CITY+"%' and stationid not like '5%' and county like '"+station.getStationname()+"%'");
//                    selectParam.put("method", "smallscale_station");
//                    selectParam.put("sqlType", "select");
//                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
//                    String message1 = pc.processRequest(selectParam);
//                    dataList = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<smallscale_station>>() {
//                    });
//                    dataMap.put(station.getStationname(),dataList);
//                }
//            }
//        } catch (Exception e) {
//            // TODO: handle exception
//        }
//        return dataMap;
//    }
    @Override
    public List<smallscale_station> getSmallScaleStation() {
    // TODO 乡镇站点
    List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
    List<smallscale_station> dataList = new ArrayList<smallscale_station>();
    try {
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        selectRequest.setParam(
                String.format("city like '%s%%' ", DbConfig.CITY));
        selectParam.put("method", "smallscale_station");

        selectParam.put("sqlType", "select");
        selectParam.put("param", JsonUtil.object2Json(selectRequest));
        String message = pc.processRequest(selectParam);
        dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
        });
        // 赋值
        if (dataList.size() > 0) {
            for (smallscale_station station : dataList) {
                SmallScaleStation scaleStation = new SmallScaleStation();

                scaleStation.setCountry(station.getCountry());
                resultList.add(scaleStation);
            }
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
    return dataList;
}
    @Override
    public List<river_basin> Getvalley(String valley) {
        List<river_basin> dataList = new ArrayList<river_basin>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(String.format(" name = '%s'", valley));
            selectParam.put("method", "river_basin");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<river_basin>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public Object getCity() {
        // TODO 县点
        List<adminCode> resultList = new ArrayList<adminCode>();
        List<admin_code> dataList = new ArrayList<admin_code>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" length(advcode)=6 and advcode like'" + DbConfig.advCode.substring(0, 4) + "%' ");
            selectParam.put("method", "admin_code");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<admin_code>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (admin_code admin : dataList) {
                    adminCode adminCode = new adminCode();

                    adminCode.setAdvcode(admin.getAdvcode());
                    adminCode.setAdvname(admin.getAdvname());
                    resultList.add(adminCode);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public Object getDecision(String producttype) {
        List<summary_product> resultList = new ArrayList<summary_product>();
        List<summary_product> dataList = new ArrayList<summary_product>();

        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            columns.add("id ");
            columns.add("productname ");
            columns.add("producttype2 ");
            columns.add("maketime ");
            selectRequest.setColumns(columns.toArray(new String[columns.size()]));
            selectRequest.setParam(" producttype =  '" + producttype + "'");
            selectParam.put("method", "summary_product");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<summary_product>>() {
            });
            if (dataList.size() > 0) {
                for (summary_product summaryProduct : dataList) {
                    summary_product summaryProduct1 = new summary_product();
                    SimpleDateFormat sdfInput = new SimpleDateFormat("yyyy-MM-dd"); // 假设输入格式是这个
                    Date maketimeDate = sdfInput.parse(summaryProduct.getMaketime());
                    summaryProduct1.setMaketime(sdfInput.format(maketimeDate));
                    summaryProduct1.setId(summaryProduct.getId());
                    summaryProduct1.setProducttype2(summaryProduct.getProducttype2());
                    summaryProduct1.setProductname(summaryProduct.getProductname());
                    resultList.add(summaryProduct1);
                }
            }
    } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return resultList;
        }

    @Override
    public Map<String, Object> getNowDate(String sql)throws Exception {
        Map<String, Object> result = new HashMap<>();
        // 使用 try-with-resources 自动管理资源
        try (Connection connection = getConnection();
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery(sql)) {
            // 处理查询结果
            while (resultSet.next()) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("temp", resultSet.getString("tem") != null && !resultSet.getString("tem").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("tem")))) : 0.0);
                map.put("bestWind", resultSet.getString("win_s_avg_2mi") != null && !resultSet.getString("win_s_avg_2mi").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("win_s_avg_2mi")))) : 0.0);
                map.put("maxWind", resultSet.getString("win_s_avg_10mi") != null && !resultSet.getString("win_s_avg_10mi").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("win_s_avg_10mi")))) : 0.0);
                map.put("oneVis", resultSet.getString("vis_hor_1mi") != null && !resultSet.getString("vis_hor_1mi").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("vis_hor_1mi")))) : 0.0);
                result.putAll(map);
            }

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }

        return result;
    }

    @Override
    public Map<String, Object> getNowDate1(String sql) throws Exception {
        Map<String, Object> result = new HashMap<>();
        // 使用 try-with-resources 自动管理资源
        try (Connection connection = getConnection();
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery(sql)) {
            // 处理查询结果
            while (resultSet.next()) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("oneHour", resultSet.getString("value") != null && !resultSet.getString("value").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("value")))) : 0.0);
                result.putAll(map);
            }

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }

        return result;
    }

    @Override
    public Map<String, Object> getNowDate2(String sql) throws Exception {
        Map<String, Object> result = new HashMap<>();
        // 使用 try-with-resources 自动管理资源
        try (Connection connection = getConnection();
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery(sql)) {
            // 处理查询结果
            while (resultSet.next()) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("DayHour", resultSet.getString("value") != null && !resultSet.getString("value").equals("-65535") ?
                        Double.parseDouble(String.format("%.1f", Double.parseDouble(resultSet.getString("value")))) : 0.0);
                result.putAll(map);
            }

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }

        return result;
    }

    // @Override
    // public String getStationId(String county) {
    //     String stationId = null;  // 用于存储提取的 stationId
    //     try {
    //         Map<String, String> selectParam = new HashMap<>();
    //         RequestDataBySelect selectRequest = new RequestDataBySelect();
    //         List<String> columns = new ArrayList<>();
    //         columns.add("stationid");  // 只请求 stationid 字段
    //         selectRequest.setColumns(columns.toArray(new String[0]));
    //         selectRequest.setParam("county =  '" + county + "' AND stationid like  '5%'");
    //         selectParam.put("method", "smallscale_station");
    //         selectParam.put("sqlType", "select");
    //         selectParam.put("param", JsonUtil.object2Json(selectRequest));
    //
    //         // 发送请求并获取结果
    //         String message = pc.processRequest(selectParam);
    //         List<smallscale_station> dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {});
    //
    //         if (dataList != null && !dataList.isEmpty()) {
    //             // 只提取第一个 stationid
    //             stationId = dataList.get(0).getStationid();
    //         }
    //     } catch (Exception e) {
    //         throw new RuntimeException(e);
    //     }
    //     return stationId;  // 返回第一个找到的 stationid
    // }

    // @Override
    // public HashMap<String, Object> getNowDate(String startTime, String stationId) {
    //     HashMap<String, Object> map = new HashMap<>();
    //     List<MsgMediumSmallScale> dataList = new ArrayList<MsgMediumSmallScale>();
    //     try {
    //         Map<String, String> selectParam = new HashMap<String, String>();
    //         RequestDataBySelect selectRequest = new RequestDataBySelect();
    //         List<String> columns = new ArrayList<String>();
    //         columns.add("drybulbtemp ");
    //         columns.add("rain");
    //         columns.add("relhumidity");
    //         columns.add("stationpress");
    //         columns.add("visibility");
    //         selectRequest.setColumns(columns.toArray(new String[columns.size()]));
    //         selectRequest.setParam(" observtime =  '" + startTime + "' AND stationid = '" + stationId+"'");
    //         selectParam.put("method", "msgmediumsmallscale");
    //         selectParam.put("sqlType", "select");
    //         selectParam.put("param", JsonUtil.object2Json(selectRequest));
    //         String message = pc.processRequest(selectParam);
    //         dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {
    //         });
    //
    //         if (dataList.size() > 0) {
    //             for (MsgMediumSmallScale msgMediumSmallScale : dataList) {
    //                 BigDecimal drybulbtempValue = new BigDecimal(msgMediumSmallScale.getDrybulbtemp());
    //                 drybulbtempValue = drybulbtempValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("drybulbtemp", drybulbtempValue.doubleValue());
    //
    //                 // 截取 oneHRain 到小数点后一位
    //                 BigDecimal rainValue = new BigDecimal(msgMediumSmallScale.getRain());
    //                 rainValue = rainValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("oneHRain", rainValue.doubleValue());
    //
    //                 // 截取 relhumidity 到小数点后一位
    //                 BigDecimal relhumidityValue = new BigDecimal(msgMediumSmallScale.getRelhumidity());
    //                 relhumidityValue = relhumidityValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("relhumidity", relhumidityValue.doubleValue());
    //
    //                 // 截取 stationpress 到小数点后一位
    //                 BigDecimal stationpressValue = new BigDecimal(msgMediumSmallScale.getStationpress());
    //                 stationpressValue = stationpressValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("stationpress", stationpressValue.doubleValue());
    //
    //                 // 截取 visibility 到小数点后一位
    //                 BigDecimal visibilityValue = new BigDecimal(msgMediumSmallScale.getVisibility());
    //                 visibilityValue = visibilityValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("visibility", visibilityValue.doubleValue());
    //             }
    //         }else {
    //                 map.put("drybulbtemp", 0.0);
    //                 map.put("oneHRain",0.0);
    //                 map.put("relhumidity",0.0);
    //                 map.put("stationpress",0.0);
    //                 map.put("visibility", 0.0);
    //         }
    //     } catch (Exception e) {
    //         throw new RuntimeException(e);
    //     }
    //     return map;
    // }

    // @Override
    // public HashMap<String, Object> getNowDate1(String startTime, String endTime, String stationId) {
    //     HashMap<String, Object> map = new HashMap<>();
    //     List<MsgMediumSmallScale> dataList = new ArrayList<MsgMediumSmallScale>();
    //     try {
    //         Map<String, String> selectParam = new HashMap<String, String>();
    //         RequestDataBySelect selectRequest = new RequestDataBySelect();
    //         List<String> columns = new ArrayList<String>();
    //         columns.add("COALESCE(SUM(rain),1) AS rain");
    //         selectRequest.setColumns(columns.toArray(new String[columns.size()]));
    //         selectRequest.setParam(" observtime >=  '" + startTime + "'AND observtime <=  '"+ endTime+"' AND stationid = '" + stationId+"'");
    //         selectParam.put("method", "msgmediumsmallscale");
    //         selectParam.put("sqlType", "select");
    //         selectParam.put("param", JsonUtil.object2Json(selectRequest));
    //         String message = pc.processRequest(selectParam);
    //         dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {
    //         });
    //         if (dataList.size() > 0) {
    //             for (MsgMediumSmallScale msgMediumSmallScale : dataList) {
    //                 BigDecimal relhumidityValue = new BigDecimal(msgMediumSmallScale.getRain());
    //                 relhumidityValue = relhumidityValue.setScale(1, RoundingMode.HALF_UP);
    //                 map.put("tfHRain", relhumidityValue.doubleValue());
    //             }
    //
    //
    //
    //         }
    //     } catch (Exception e) {
    //         throw new RuntimeException(e);
    //     }
    //     return map;
    // }
    private static Connection getConnection() throws SQLException, ClassNotFoundException, IOException {
        try {
            Properties prop = new Properties();
            InputStream in = ComDisplayServiceImpl.class.getClassLoader().getResourceAsStream("dbconfig.properties");
            prop.load(in);
            Connection connection;
            Class.forName("org.postgresql.Driver");
            return DriverManager.getConnection(prop.getProperty("postgresql.master.url"), prop.getProperty("postgresql.username"), prop.getProperty("postgresql.password"));

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }
    }
    private static Connection getConnection1() throws SQLException, ClassNotFoundException, IOException {
        try {
            Properties prop = new Properties();
            InputStream in = ComDisplayServiceImpl.class.getClassLoader().getResourceAsStream("dbconfig.properties");
            prop.load(in);
            Connection connection;
            Class.forName("org.postgresql.Driver");
            return DriverManager.getConnection(prop.getProperty("postgresql.servant.url"), prop.getProperty("postgresql.username"), prop.getProperty("postgresql.password"));

        } catch (Exception e) {
            log.error(e.getMessage());
            throw e;
        }
    }
}
